package com.compass.mobile.presenters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.leanback.widget.Presenter
import com.compass.mobile.R
import com.compass.mobile.framework.ext.gone
import com.compass.mobile.models.Doctor
import com.compass.mobile.models.Title
import dp2px
import setUrlCircle
import setUrlRound

/**
 * Description： 专栏Presenter
 * Date:2024/5/16 16:35
 */
class SpecialColumnPresenter : Presenter() {

    private var finalWidth: Int? = null
    fun setFinalWidth(finalWidth: Int?) {
        this.finalWidth = finalWidth
    }
    override fun onCreateViewHolder(viewGroup: ViewGroup): ViewHolder {
        val view = LayoutInflater.from(viewGroup.context)
            .inflate(R.layout.item_special_column, viewGroup, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) {
        if (item is Doctor) {
            val vh = viewHolder as ViewHolder
            vh.layoutParams.width = finalWidth!!
            vh.itemView.layoutParams = vh.layoutParams
            vh.tvTitle.text = item.name
            vh.tvValue.text=item.meritIllness
            vh.imgDoctor.gone()
//            vh.imgDoctor.setUrlRound(item.avatar,dp2px(5f))
        }
    }

    override fun onUnbindViewHolder(viewHolder: Presenter.ViewHolder) {
    }


    class ViewHolder(view: View) : Presenter.ViewHolder(view) {
        var tvTitle: TextView = view.findViewById(R.id.tv_title)
        var imgDoctor: ImageView = view.findViewById(R.id.imgDoctor)
        var tvValue: TextView = view.findViewById(R.id.tvValue)
        var itemView: ConstraintLayout = view.findViewById(R.id.itemView)
        var layoutParams: ViewGroup.LayoutParams = itemView.layoutParams
    }
}
